<?php

namespace backend\models\active;

use common\models\active\ActiveCouponReceiveModel;
use common\models\active\ActiveCouponModel;

/**
 * Desc 优惠券活动模型
 */
class ActiveCouponReceive extends ActiveCouponReceiveModel
{

    public static function getUnionAll($condition = [], $page = 1, $page_size = 20, $order_by = 'acr.id DESC', $select = [])
    {
        $query = ActiveCouponReceiveModel::find()
            ->alias('acr')
            ->leftJoin(ActiveCouponModel::tableName() . ' ac', 'ac.id=acr.active_coupon')
            ->select($select);
        list($offset, $limit) = \common\tools\Util::getLimit($page, $page_size);
        if ($condition) {
            $query->where($condition);
        }
        $data['total'] = intval($query->count());
        $query->offset($offset)->limit($limit)->orderBy($order_by);
        $data['list'] = $query->asArray()->all();
        return $data;
    }
}
